<!--{template librarylist/pc/components/right/file/js}-->
<!--{template librarylist/pc/components/right/chatJs}-->
<!--{template librarylist/pc/components/right/AikeysJs}-->
<script>
	let RightMixin = {
		data(){
			return {
				RightWidth:320,
				RightType:'',
				RightActiveRid:[],
				RightActivefid:[],
				RightData:{
					img:[],
					color:[],
					title:'',
					message:'',
					link:'',
					level:0,
					format:'',
					size:'',
					foldersize:'',
					foldenum:'',
					grade:0,
					btime:'',
					mtime:'',
					dateline:'',
					fileds:[],
					filedsData:[],
					folder:[],
					langkey:null,
					Aikey:{},
					Aichat:false,
					filetype:'',
					filenamewirte:false,
					allowedit:false,
				},
				Rightallowcover:0,
				RightNameaiload:false,
				RightPostParam:null,
				RightAikey:0
			}
		},
		mixins:[RightFileMixin,RightChatMixin,AikeysMixin],
		methods:{
			async RightFileAikeyChange(data,key,flag){
				let self = this;
				let param = {
					rid:this.RightActiveRid.join(','),
					aiKey:key,
					tplid:data.tplid
				}
				if(flag == 'name'){
					this.RightNameaiload = true;
				}else{
					var curr = this.RightData.filedsData.find(function(current){
						return current.flag == flag;
					});
					if(!curr)return false;
					curr.aiload = true;
				}
				let {data :res} = await axios.post(MOD_URL+'&op=library&do=ajax&operation=imageAiData',param);
				if(flag == 'tag'){
					curr.aiload = false;
				}else if(flag == 'name'){
					this.RightNameaiload = false;
				}else{
					curr.aiload = false;
				}
				if(res.success){
					if(res.data.flag == 'tag'){
						curr.data = res.data.value;
						curr.value = res.data.value.map(function(item,index){
							return item.tid;
						}).join(',').split(',');
					}else if(flag == 'name'){
						this.RightData.title = res.data.value;
						self.$refs.RefImageLayout.UpdateData(this.RightActiveRid[0],'name',res.data.value);

					}else{
						curr.value = res.data.value;
					}
					
				}else{
					self.$message({
						dangerouslyUseHTMLString:true,
						message:res.msg,
						type:'error'
					});
				}
				
			},
			async RightGetData(){
				let self = this;
				let url = '';
				let param = {
					appid:this.DocumentAppid,
					hassub:this.hassub
				};

				if(this.RightType == 'file'){
					url = MOD_URL+'&op=library&do=rightdata&operation=getfiledata';
				}else{
					url = MOD_URL+'&op=library&do=rightdata&operation=getfolderdata';
				}
				if(this.RightType == 'file'){
					param['rids'] = this.RightActiveRid.join(',');
				}else if(this.RightType == 'notclassify'){
					param['nofolder'] = 1;
				}else if(this.RightType == 'nottag'){
					param['notag'] = 1;
				}else if(this.RightType == 'folder'){
					param['fid'] = this.RightActivefid.join(',');
				}else if(this.RightType == 'recycle'){
					param['isrecycle'] = 1;
				}
				this.answerloading = false;

				if(this.RightPostParam){
					this.RightPostParam();
				}
				let CancelToken = axios.CancelToken;
				axios.post(url, param,{
					cancelToken: new CancelToken(function executor(c) {
					    self.RightPostParam = c;
					})
				}).then(function ({data :res}) {
					self.RightPostParam = '';
					if(res.Aichat){
						self.RightData.Aichat = true;
						self.answerParam = {
							params:res.Aichat.params?res.Aichat.params:'',
							recordurl:res.Aichat.recordurl?res.Aichat.recordurl:'',
							type:res.Aichat.type?res.Aichat.type:'',
							url:res.Aichat.url?res.Aichat.url:'',
							delhistoryurl:res.Aichat.delhistoryurl?res.Aichat.delhistoryurl:''
						}
					}else{
						self.RightData.Aichat = false;
					}
					self.RightData.filenamewirte = res.filenamewirte?res.filenamewirte:false;
					self.RightData.allowedit = res.allowedit?res.allowedit:false;
					self.Rightallowcover = parseFloat(res.allowcover)?res.allowcover:0;
					self.RightData.filetype = res.filetype?res.filetype:'';
					self.RightData.langkey = res.langkey?res.langkey:'';
					self.RightData.Aikey = res.Aikey?res.Aikey:{};
					if(self.RightType == 'file'){
						if(res){
							self.RightData.fileds = res.fileds || [];
							self.RightData.filedsData = [];
							if(self.RightData.fileds.length){
								for (let index = 0; index < self.RightData.fileds.length; index++) {
									const element = self.RightData.fileds[index];
									if(parseInt(element.checked) == 0 || !element.flag)continue;
									if(element.type == "tabgroup"){
										let tval = [];
										let tdata = [];
										for (const key in res[element.flag]) {
											const felement = res[element.flag][key];
											tval.push(felement.tid);
											tdata.push(felement);
										}
										self.RightData.filedsData.push({
											value:tval,
											flag:element.flag,
											id:element.flag.replace('tabgroup_',''),
											name:element.name,
											iframe:'',
											data:tdata,
											aiload:false
										})
									
									}else if(element.flag == "fid"){
										let data = [];
										for(let f in res.foldernames){
											data.push({
												fid:f,
												fname:res.foldernames[f]['fname'],
												pathkey:res.foldernames[f]['pathkey'],
											});
										}
										self.RightData.filedsData.push({
											value:data,
											flag:element.flag,
											name:element.name,
											aiload:false
										});
										self.RightData.folder=data;
									}else if(element.flag == "tag"){
										let data = [];
										let val = [];
										if(res[element.flag]){
											for (const key in res[element.flag]) {
												if (Object.hasOwnProperty.call(res[element.flag], key)) {
													const helement = res[element.flag][key];
													data.push({
														tid:key,
														tagname:helement
													});
													val.push(key)
												}
											}

										}
										self.RightData.filedsData.push({
											value:val,
											flag:element.flag,
											name:element.name,
											data:data,
											aiload:false
										})
									}else if(element.flag == "multiselect"){
										self.RightData.filedsData.push({
											value:res[element.flag] || [],
											flag:element.flag,
											name:element.name,
											aiload:false
										});
									}else if(element.flag == "preview"){
										self.RightData.filedsData.push({
											value:res[element.flag] || [],
											flag:element.flag,
											name:element.name,
											num:0
										});
										if(self.RightData.allowedit){
											self.$nextTick(function(){
												self.RightPreviewSortable()
											});
										}
										
									}else if(element.flag == "lang"){
										self.RightData.filedsData.push({
											value:res[element.flag] || '',
											flag:element.flag,
											name:element.name,
											data:element.options,
										})
									}else if(element.flag == "sys"){
										let values = [];
										if(res[element.flag]){
											values = res[element.flag].split(',');
										}
										self.RightData.filedsData.push({
											value:values,
											flag:element.flag,
											name:element.name,
											data:values,
										})
									}else{
										self.RightData.filedsData.push({
											value:res[element.flag] || '',
											flag:element.flag,
											name:element.name,
											data:[],
											aiload:false
										})
									}

									}
							}
							if(self.RightActiveRid.length>1){
								self.RightData.img = [];
								for(var t in res.icondata){
									if(t>=6){
										continue;
									}
									self.RightData.img.push(res.icondata[t]);
								}
								self.RightData.level = res.level?parseInt(res.level):0;
								self.RightData.foldersize = res.size;
								self.RightData.link = res.link;
								self.RightData.message = res.desc;
							}else{
								self.RightData.img = [res.icondata];
								self.RightData.color = [];
								for(var i in res.colors){
									self.RightData.color.push('#'+res.colors[i]);
								}
								self.RightData.title = res.name;
								self.RightData.message = res.desc;
								self.RightData.link = res.link;
								self.RightData.format = res.ext;
								self.RightData.size = res.width+'×'+res.height;
								self.RightData.foldersize = res.fsize;
								self.RightData.grade = parseInt(res.grade);
								self.RightData.level = res.level?parseInt(res.level):0;
								self.RightData.btime = res.btime;
								self.RightData.mtime = res.mtime;
								self.RightData.dateline = res.dateline;
							}

						}
					}else if(self.RightType == 'folder'){
						if(res){
							
							if(res.num){
								self.RightData.foldenum = res.num;
							}
							if(res.size){
								self.RightData.foldersize = res.size;
							}
							if(res.dateline){
								self.RightData.dateline = res.dateline;
							}
							self.RightData.title = res.fname;
							self.RightData.message = res.desc;
							let data = [];
							let val = [];
							if(res['tagdata']){
								for (const key in res['tagdata']) {
									const helement = res['tagdata'][key];
									data.push({
										tid:key,
										tagname:helement
									});
									val.push(key)
								}
			
							}
							self.RightData.filedsData.push({
								value:val,
								flag:'tag',
								name:'{lang label}',
								data:data
							})
						}
					}else{
						if(res){
							if(res.num){
								self.RightData.foldenum = res.num;
							}else{
								self.RightData.foldenum = 0;
							}
							if(res.size){
								self.RightData.foldersize = res.size;
							}else{
								self.RightData.foldersize = 0;
							}
						}
					}
				}).catch(function (error) {
				    console.log(error);
				});
			},
			async RightFolderNameChange(val){
				let self = this;
				let res = await axios.post(MOD_URL+'&op=library&do=folder&operation=rename',{
					fid: this.RightActivefid[0],
					name:val
				});
				if(self.$refs.ImageFileRef){
					self.$refs.ImageFileRef.EditData({
						fid:this.RightActivefid[0],
						type:'fname',
						value:val
					});
				}
				let node = self.$refs.LeftTreeRef.getNode(this.RightActivefid[0]);
				if(node){
					node.data.fname = val;
					node.data.pfname = val;
				}
			},
			RightFolderNameLanguageChange(val){
				let self = this;
				if(self.$refs.ImageFileRef){
					self.$refs.ImageFileRef.EditData({
						fid:this.RightActivefid[0],
						type:'fname',
						value:val
					});
				}
				this.RightData.title = val;
				let node = self.$refs.LeftTreeRef.getNode(this.RightActivefid[0]);
				if(node){
					node.data.fname = val;
					node.data.pfname = val;
				}
			},
			RightParamClean(type){
				this.answer = '';
                this.answerBox = false;
                this.answerData = [];
				this.answerParam = {
                    params:'',
                    recordurl:'',
                    type:'',
                    url:'',
					delhistoryurl:''
                };
				this.RightNameaiload = false;
				if(type){
					this.RightData = {
						img:[],
						color:[],
						title:'',
						message:'',
						link:'',
						level:0,
						format:'',
						size:'',
						foldersize:'',
						foldenum:'',
						grade:0,
						btime:'',
						mtime:'',
						dateline:'',
						fileds:[],
						filedsData:[],
						folder:[],
						langkey:null,
						Aikey:{},
						Aichat : false,
						filetype:'',
						filenamewirte:false
					}

					return false;
				}
				this.RightType = '';
				this.RightActiveRid = [];
				this.RightActivefid = [];
				this.RightData = {
					img:[],
					color:[],
					title:'',
					message:'',
					link:'',
					level:0,
					format:'',
					size:'',
					foldersize:'',
					foldenum:'',
					grade:0,
					btime:'',
					mtime:'',
					dateline:'',
					fileds:[],
					filedsData:[],
					folder:[],
					langkey:null,
					Aikey:{},
					Aichat : false,
					filetype:'',
					filenamewirte:false
				}
			},
			RightdragControllerDiv(){
				var self = this;
				var boxw = document.body.clientWidth;
				var fboxw = parseInt(boxw/3);
				// 鼠标按下事件
				document.onmousemove = function(e) {
					var DocumentLeftWidth = e.clientX+1;
					DocumentLeftWidth = boxw-DocumentLeftWidth;
					if(DocumentLeftWidth>fboxw){
						DocumentLeftWidth = fboxw;
					}else if(DocumentLeftWidth<260){
						DocumentLeftWidth = 260;
					}
					self.RightWidth = DocumentLeftWidth;
					return false;
				};
				document.onmouseup = function() {
					document.onmousemove = null;
					document.onmouseup = null;
					if(self.LeftCurrenType != 'tags' && self.LeftCurrenType != 'member'){
						self.$refs.RefImageLayout.updateImageData();
					}
					return false;
				};
				return false;
			}
		}
	};
</script>